package com.jkgj.skykingkong.tms.domain.model;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author Xuegui Yuan
 */
@Component
public class DomainRegistry implements ApplicationContextAware {
  private static ApplicationContext applicationContext;

  public static PasswordEncoder passwordEncoder() {
    return applicationContext.getBean(PasswordEncoder.class);
  }


  @Override
  public synchronized void setApplicationContext(
      ApplicationContext applicationContext) throws BeansException {
    if (DomainRegistry.applicationContext == null) {
      DomainRegistry.applicationContext = applicationContext;
    }
  }
}
